FROM vipharbor.99bill.com/base/rhel7:7.9-1011 AS builder

ENV APP=k8s-webhook-setenvresources
ENV URL_ADDRESS=https://gitee.com/rogax/$(APP).git
ENV GOVER=1.23.0
ENV GOPATH=/go
ENV GO111MODULE=on
ENV GOPROXY=https://goproxy.cn,direct
ENV PATH=$GOPATH/bin:/usr/local/go/bin:$PATH

RUN curl -sSL -O https://golang.google.cn/dl/$(GOVER).linux-amd64.tar.gz &&
        rm -rf /usr/local/go && tar -C /usr/local -xzf $(GOVER).linux-amd64.tar.gz

RUN yum install -y git && yum install -y gcc gcc-c++ make && mkdir -p /go/src
RUN cd /go/src && git clone URL_ADDRESS
WORKDIR /go/src/$(APP)
RUN go mod tidy
RUN go build -o /tmp/$(APP)

FROM vipharbor.99bill.com/base/rhel7:7.9-1011
WORKDIR /opt
COPY builder:/tmp/k8s-webhook-setenvresources .
CMD ["./k8s-webhook-setenvresources", "--port", "8443", "--cert-dir", "/var/lib/k8s-webhook-setenvresources/certs", "--tls-cert", "/etc/opt/tls.crt", "--tls-key", "/etc/opt/tls.key"]